var _NumberAnimate = require("/first_duoduoke/utils/NumberAnimate"), _NumberAnimate2 = _interopRequireDefault(_NumberAnimate);

function _interopRequireDefault(e) {
    return e && e.__esModule ? e : {
        default: e
    };
}

App({
    onLaunch: function(e) {
        var t = this;
        wx.getSystemInfo({
            success: function(e) {
                t.globalData.navHeight = e.statusBarHeight + 46, t.platform = e.platform, t.system = e.system;
            },
            fail: function(e) {
                console.log(e);
            }
        }), void 0 !== e.query.from_uid && e.query.from_uid && (this.globalData.from_uid = e.query.from_uid), 
        void 0 !== e.query.from_act && e.query.from_act && (this.globalData.from_act = e.query.from_act), 
        this.innerAudioContext = wx.createInnerAudioContext(), this.innerAudioContext.autoplay = !1, 
        this.innerAudioContext.src = this.siteInfo.siteroot.replace("app/index.php", "") + "/addons/first_duoduoke/resource/images/app/coin.mp3", 
        this.innerAudioContext.onPlay(function() {
            console.log("开始播放音频");
        }), this.innerAudioContext.onError(function(e) {
            console.log("音频播放失败:" + e.errCode + "-" + e.errMsg), console.log();
        });
    },
    onShow: function() {},
    onHide: function() {
        this.globalData.from_uid && (this.globalData.from_uid = !1, this.globalData.from_act = !1), 
        !1 === this.globalData.showSmart && (this.globalData.showSmart = !0);
    },
    innerAudioContext: "",
    util: require("we7/resource/js/util.js"),
    config: require("first_duoduoke/utils/config.js"),
    siteInfo: require("siteinfo.js"),
    formIds: [],
    platform: !1,
    system: !1,
    globalData: {
        userInfo: !1,
        navHeight: 0,
        setting: !1,
        showVip: !1,
        showRed: !1,
        from_uid: !1,
        from_act: !1,
        showSmart: !0,
        hotTab: !1,
        show_once_subtip: !1,
        show_open_adv: !1
    },
    getImgUrl: function() {
        return getApp().siteInfo.siteroot.replace("app/index.php", "") + "/addons/first_duoduoke/resource/images/app/";
    },
    goIndex: function() {
        wx.switchTab({
            url: "/first_duoduoke/pages/index/index"
        });
    },
    reUserInfo: function() {
        var e = getCurrentPages(), t = e[e.length - 1], o = getApp(), a = wx.getStorageSync("userInfo");
        !o.globalData.userInfo && a ? o.util.request({
            url: "entry/wxapp/getUserInfo",
            showLoading: !1,
            success: function(e) {
                (e = e.data.data).avatar = a.wxInfo.avatarUrl, e.nickName = a.wxInfo.nickName, o.globalData.userInfo = e, 
                "first_duoduoke/pages/index/index" == t.route && o.globalData.setting && (t.isShowVip(), 
                t.isShowRed()), "first_duoduoke/pages/red-envelope/draw" == t.route && t.getReceiveRpw();
            }
        }) : "first_duoduoke/pages/index/index" == t.route && o.globalData.setting && (t.isShowVip(), 
        t.isShowRed());
    },
    checkLogin: function() {
        var e = getCurrentPages(), s = e[e.length - 1], n = getApp();
        n.util.getUserInfo(function(a) {
            s.data.showLoginModal && s.setData({
                showLoginModal: !1
            }), n.util.request({
                url: "entry/wxapp/getUserInfo",
                showLoading: !1,
                success: function(e) {
                    var t, o;
                    (e = e.data.data).avatar = a.wxInfo.avatarUrl, e.nickName = a.wxInfo.nickName, n.globalData.userInfo = e, 
                    "first_duoduoke/pages/my/my" == s.route && s.setData({
                        uInfo: e
                    }, function() {
                        s.getBdPhone();
                    }), "first_duoduoke/pages/cash/cash" == s.route && s.setData({
                        uInfo: e
                    }), "first_duoduoke/pages/goods/goods" == s.route && s.getGoodsDetail(), "first_duoduoke/pages/find/find" == s.routr && s.zanSaleWallpaper(), 
                    "first_duoduoke/pages/partake/partake" == s.route && s.setData({
                        isLogin: !0
                    }), "first_duoduoke/pages/task/task" == s.route && (s.setData({
                        isLogin: !0
                    }), t = new _NumberAnimate2.default({
                        from: e.money,
                        speed: 600,
                        refreshTime: 100,
                        decimals: 2,
                        onUpdate: function() {
                            s.setData({
                                "uInfo.money": t.tempValue
                            });
                        }
                    }), o = new _NumberAnimate2.default({
                        from: e.coin,
                        speed: 600,
                        refreshTime: 100,
                        decimals: 0,
                        onUpdate: function() {
                            s.setData({
                                "uInfo.coin": o.tempValue
                            });
                        }
                    }), s.toPageTop(), n.innerAudioContext.play()), "first_duoduoke/pages/welfare/welfare" == s.route && s.checkReceive(), 
                    "first_duoduoke/pages/red-envelope/draw" == s.route && s.getReceiveRpw(), "first_duoduoke/pages/red-envelope/red-envelope" == s.route && s.getRedPacketWall(), 
                    "first_duoduoke/pages/turntable/turntable" == s.route && s.getRotaryInfo(), "first_duoduoke/pages/treasure/treasure" == s.route && s.getSpeedLootingInfo(), 
                    "first_duoduoke/pages/rush-buy/rush-buy" == s.route && s.getRushBuyInfo(), "first_duoduoke/pages/rush-buy/rush-goodsdetails" == s.route && s.getThisRushBuyGood(), 
                    "first_duoduoke/pages/exemption/exemption" == s.route && s.getFreeRedInfo(), "first_duoduoke/pages/morning/morning" == s.route && s.getMorningInfo(), 
                    "first_duoduoke/pages/hot/hot" == s.route && s.onPullDownRefresh(), n.checkUserSub("1|2|3");
                }
            });
        });
    },
    toChainpage: function() {
        console.log("ssss"), wx.navigateTo({
            url: "/first_duoduoke/pages/index/notice"
        });
    },
    loginAfter: function(e) {
        "getUserInfo:ok" == e.detail.errMsg && ((e = getCurrentPages())[e.length - 1], getApp().checkLogin());
    },
    loginCancel: function() {
        var e = getCurrentPages();
        e[e.length - 1].setData({
            showLoginModal: !1
        });
    },
    showInfo: function(e, t) {
        e.setData({
            info: {
                show: !0,
                cnt: t
            }
        });
    },
    hideInfo: function(e) {
        e.setData({
            info: {
                show: !1
            }
        });
    },
    oneKeyZl: function(e) {
        wx.navigateTo({
            url: "/first_duoduoke/pages/index/turn-chain?content=" + encodeURIComponent(e)
        });
    },
    showSmart: function(a, s) {
        !1 !== s.globalData.showSmart && (a.data.show_open_adv || s.globalData.setting && 1 != s.globalData.setting.audit_switch && wx.getClipboardData({
            success: function(e) {
                var t, o;
                e.data && " " != e.data && (t = s.globalData.setting, o = e.data, /^\d{19}$/g.test(o) && 1 == t.tb_open ? wx.showModal({
                    title: "系统信息",
                    content: "系统检测到以下内容：[" + o + "]，类似“淘宝”订单号，点击确定去“找回订单”",
                    showCancel: !0,
                    confirmColor: "#f43f6c",
                    confirmText: "确定",
                    complete: function(e) {
                        e.confirm && wx.navigateTo({
                            url: "/first_duoduoke/pages/orders/orders?source=6&tb_order_sn=" + o,
                            success: function() {
                                wx.setClipboardData({
                                    data: " ",
                                    success: function() {
                                        wx.hideLoading();
                                    }
                                });
                            }
                        }), e.cancel && s.disGoods(s, o, a, t);
                    }
                }) : s.disGoods(s, o, a, t));
            },
            fail: function(e) {
                console.log(e, "获取剪切版内容失败");
            }
        }));
    },
    disGoods: function(e, t, o, a) {
        e.util.request({
            url: "entry/wxapp/getDisGoods",
            data: {
                content: t
            },
            showLoading: !1,
            success: function(e) {
                o.setData({
                    rpReward: !1,
                    showVip: !1,
                    showShareStatus: !1,
                    showShareImg: !1,
                    enve: !1
                }), "ok" == e.data.message ? (wx.vibrateShort({
                    type: "heavy"
                }), o.setData({
                    smartSou: {
                        showg: !0,
                        goods: e.data.data,
                        appletKeyword: a.appletKeyword,
                        content: t
                    }
                }, function() {
                    wx.setClipboardData({
                        data: " ",
                        success: function() {
                            wx.hideLoading();
                        }
                    });
                })) : o.setData({
                    smartSou: {
                        show: !0,
                        key: t,
                        tb_open: a.tb_open,
                        kl_open: a.kl_open,
                        jd_open: a.jd_open,
                        mg_open: a.mg_open,
                        vip_open: a.vip_open,
                        sn_open: a.sn_open
                    }
                }, function() {
                    wx.setClipboardData({
                        data: " ",
                        success: function() {
                            wx.hideLoading();
                        }
                    });
                });
            }
        });
    },
    confirmSmart: function(e, t) {
        var o = e.data.smartSou.key;
        wx.navigateTo({
            url: "/first_duoduoke/pages/search/search?keyword=" + o + "&source=" + t,
            success: function() {
                e.setData({
                    smartSou: {
                        show: !1
                    }
                });
            }
        });
    },
    reMgToken: function(e) {
        getApp().util.request({
            url: "entry/wxapp/reMgToken",
            showLoading: !1,
            success: function(e) {}
        });
    },
    hideSmart: function(e) {
        e.setData({
            smartSou: {
                show: !1,
                showg: !1
            }
        });
    },
    checkUserSub: function(l) {
        var g = 1 < arguments.length && void 0 !== arguments[1] && arguments[1], f = getApp();
        if (1 != f.globalData.setting.sub_msg_switch) return !1;
        !1 === g && 1 == f.globalData.setting.sub_trouble_switch && !1 !== f.globalData.show_once_subtip || f.util.request({
            url: f.util.url("entry/wxapp/getUserSub"),
            showLoading: !1,
            data: {
                key: l
            },
            method: "POST",
            success: function(e) {
                var t = [ f.globalData.setting.batch_tempid, f.globalData.setting.bind_tempid, f.globalData.setting.withdrawal_tempid, f.globalData.setting.booked_tempid, f.globalData.setting.settle_tempid, f.globalData.setting.morning_tempid ], o = [ "【优惠券领取通知】", "【关系绑定通知】", "【提现审核结果通知】", "【佣金入账通知】", "【结算佣金通知】", "【早起打卡通知】" ], a = [], s = [];
                if ("number" == typeof l) a = [ t[l - 1] ], s = [ o[l - 1] ]; else for (var n in l = l.split("|")) a.push(t[l[n] - 1]), 
                s.push(o[l[n] - 1]);
                var i = e.data.data, r = 0, u = [], d = [], c = [];
                for (n in i) i[n][0] < 1 && (u.push(a.splice(r, 1, "")[0]), d.push(s.splice(r, 1, "")[0]), 
                "number" != typeof l && c.push(l.splice(r, 1, "")[0])), r++;
                1 < u && f.system && (e = f.system.match(/\d+(\.\d+)?(\.\d+)?/), e = parseInt(e.replace(/\./g, "")), 
                ("ios" == f.platform && e < 706 || "android" == f.platform && e < 707) && (u.splice(1), 
                d.splice(1), "number" != typeof l && c.splice(1))), 0 < u.length && wx.showModal({
                    title: "系统提示",
                    content: "您还没有订阅" + d.join("&") + "，订阅后可收到服务消息通知，建议勾选“（√）总是允许”选框",
                    confirmColor: "#f43f6c",
                    confirmText: "直接订阅",
                    showCancel: !0,
                    cancelColor: "#00c201",
                    cancelText: "去订阅",
                    success: function(e) {
                        !1 === g && 1 == f.globalData.setting.sub_trouble_switch && (f.globalData.show_once_subtip = !0), 
                        e.confirm ? wx.requestSubscribeMessage({
                            tmplIds: u,
                            success: function(e) {
                                for (var t in console.log(e), e) {
                                    if ("reject" == e[t] || "ban" == e[t]) {
                                        wx.showToast({
                                            title: "订阅失败",
                                            icon: "none"
                                        }), wx.openSetting({
                                            withSubscriptions: !0,
                                            success: function(e) {
                                                console.log(e.authSetting);
                                            }
                                        });
                                        break;
                                    }
                                    if ("accept" == e[t]) {
                                        wx.showToast({
                                            title: "订阅成功",
                                            icon: "success"
                                        }), f.util.request({
                                            url: f.util.url("entry/wxapp/subUserMsg"),
                                            showLoading: !1,
                                            method: "POST",
                                            data: {
                                                key: "number" == typeof l ? l : c.join("|")
                                            },
                                            success: function(e) {}
                                        });
                                        break;
                                    }
                                }
                            },
                            fail: function(e) {
                                console.log(e), 20004 == e.errCode ? wx.showModal({
                                    title: "系统提示",
                                    content: "请转至“授权设置”页面打开订阅消息主开关",
                                    confirmColor: "#f43f6c",
                                    confirmText: "去打开",
                                    showCancel: !1,
                                    success: function(e) {
                                        wx.openSetting({
                                            withSubscriptions: !0,
                                            success: function() {}
                                        });
                                    }
                                }) : wx.showModal({
                                    title: "系统提示",
                                    content: "订阅发生异常，请跳转订阅消息页面进行订阅",
                                    confirmColor: "#f43f6c",
                                    confirmText: "去订阅",
                                    showCancel: !1,
                                    success: function(e) {
                                        wx.navigateTo({
                                            url: "/first_duoduoke/pages/submsg/submsg"
                                        });
                                    }
                                }), f.util.request({
                                    url: f.util.url("entry/wxapp/reportSubErr"),
                                    showLoading: !1,
                                    method: "POST",
                                    data: {
                                        err_code: e.errCode,
                                        err_msg: e.errMsg,
                                        system: f.system
                                    },
                                    success: function(e) {}
                                });
                            }
                        }) : e.cancel && wx.navigateTo({
                            url: "/first_duoduoke/pages/submsg/submsg"
                        });
                    }
                });
            }
        });
    }
});